﻿<!--#include file="../inc/conn.asp"-->
<%
sub deal_xml()
	set xml=server.createObject("msxml2.DOMDocument")
	xml.resolveExternals = false
	xml.async=false
	if(xml.load(request)) then
		return_code=xml.getelementsbytagname("return_code").item(0).text
		if return_code="SUCCESS" then
			m_order_no=xml.getelementsbytagname("out_trade_no").item(0).text
            m_order_total_fee=xml.getelementsbytagname("total_fee").item(0).text
			m_order_trade_type=xml.getelementsbytagname("trade_type").item(0).text
            m_order_bank_type=xml.getelementsbytagname("bank_type").item(0).text
            m_order_transaction_id=xml.getelementsbytagname("transaction_id").item(0).text
            m_order_time_end=xml.getelementsbytagname("time_end").item(0).Text
			'm_is_subscribe=xml.getelementsbytagname("is_subscribe").item(0).text
            m_order_nonce_str=xml.getelementsbytagname("nonce_str").item(0).text
            ' m_uid=split(m_order_nonce_str,"#z#")(0)
            m_oid=split(m_order_nonce_str,"#z#")(1)

            '查询订单并更新
            set rsObj=conn.db("select * from {pre}user_order where Id="&m_oid&"","2")
            if not rsObj.eof then
                m_id=rsObj("Id")
                m_uid=rsObj("uid")
                m_paydate=rsObj("paydate")
                m_rname=rsObj("rname")
                m_gender=rsObj("gender")
                m_idcard=rsObj("idcard")
                m_title=rsObj("title")
                m_signupkm=rsObj("signupkm")
                m_drivingcard_ctype=rsObj("drivingcard_ctype")
                m_disfee=rsObj("disfee")
                m_totalfee=money(rsObj("entryfee")-rsObj("disfee"))
                m_birthday=rsObj("birthday") : m_birthday=left(m_birthday,4)&"-"&mid(m_birthday,5,2)&"-"&right(m_birthday,2)
                m_address=rsObj("address")
                m_rphone=rsObj("rphone")
                if not isnul(m_title) then m_drivingcard_ctype="" '仅C1\C2上传增驾信息
                m_applytype="初次申领" : if not isnul(m_drivingcard_ctype) then m_applytype="增加准驾车型"
                m_signdate=FormatDate(now(),1)
                if not isnul(m_title) then m_remark=m_title&"，"
                m_remark=m_remark&"微信支付"&money(m_totalfee)
                if m_disfee>0 then m_remark=m_remark&"，优惠"&money(m_disfee)&""

                m_fuid=conn.db("select fuid from {pre}user where Id="&m_uid&"","0")(0) : m_evername="瑞科"
                if m_fuid>0 and conn.db("select count(Id) from {pre}user where Id="&m_fuid,"0")(0)>0 then
                    m_agent_name=conn.db("select agent_name from {pre}user where Id="&m_fuid,"0")(0)
                    m_jsrname=conn.db("select rname from {pre}user where Id="&m_fuid,"0")(0)
                    if not isnul(m_agent_name) then
                        m_evername=m_agent_name
                    elseif not isnul(m_jsrname) then
                        m_evername=m_jsrname
                    'else
                        'm_evername=conn.db("select rphone from {pre}user where Id="&m_fuid,"0")(0)
                    end if
                end if

                '更新订单支付信息
                rsObj("paytype")=m_order_bank_type
                rsObj("paydate")=now()
                rsObj("payno")=m_order_no
                rsObj.update
                conn.db "update {pre}user set [ustep]=0 where Id="&m_uid,"0" '更新进度

                '诺诺开票
                m_data="buyerName="&m_rname&""
                m_data=m_data&"&buyerPhone="&m_rphone&""
                m_data=m_data&"&buyerTaxNum="&m_idcard&""
                m_data=m_data&"&goodsName=驾校-培训费"
                m_data=m_data&"&remark=微信小程序（"&m_evername&"）"
                m_data=m_data&"&specType="&m_signupkm&""
                m_data=m_data&"&price="&m_totalfee&""
                m_data=m_data&"&pw="&site_invoicekey&"" '发票密钥
                m_data=m_data&"&num=1"
                m_backjson=PostURL(wx_apiurl&"/nuonuo/createinvoice.php",m_data)
                set obj=parseJSON(m_backjson)
                    if obj.code=1 then rsObj("invoice")=obj.data.serialNos : rsObj.update '更新发票流水号
                set obj=nothing

               '同步档案到蓝盾服务器
                m_data="id="&m_id&""
                m_data=m_data&"&title="&m_title&""
                m_data=m_data&"&student_name="&m_rname&""
                m_data=m_data&"&student_sex="&m_gender&""
                m_data=m_data&"&student_identitycard="&m_idcard&""
                m_data=m_data&"&student_birthday="&m_birthday&""
                m_data=m_data&"&student_homeaddress="&m_address&""
                m_data=m_data&"&student_mobphone="&m_rphone&""
                m_data=m_data&"&student_nowallowdrive="&m_drivingcard_ctype&""
                m_data=m_data&"&student_signdate="&m_signdate&""
                m_data=m_data&"&student_signarea=0003" '报名办公室，0003=培训中心
                m_data=m_data&"&booker_id=00003" '登记人，00003=小程序
                m_data=m_data&"&student_remark="&m_remark&""
                m_data=m_data&"&student_applyallowdrive="&m_signupkm&""
                m_data=m_data&"&student_evername="&m_evername&""
                m_data=m_data&"&student_status=报名入学"
                m_data=m_data&"&postalcode=fdg"
                m_data=m_data&"&student_oldstatus=报名入学"
                m_data=m_data&"&student_applytpye="&m_applytype&""
                m_data=m_data&"&enroll_type=null"
                m_backjson=PostURL(wx_apiurl&"/server/?c=upServer",m_data)
                set obj=parseJSON(m_backjson)
                    if obj.state=1 then rsObj("sync_server")=1 : rsObj.update '执行同步状态
                set obj=nothing

                '推送短信给管理员
                set rsObj=conn.db("select rphone from {pre}user where power like '%#1#%'","0")
                if not rsObj.eof then
                    if site_opensms=1 then
                        do while not rsObj.eof
                            if SUBmobile(rsObj("rphone"))=True then getSMSecode "蓝盾驾校",244148,rsObj("rphone"),""
                            rsObj.movenext
                        loop
                    end if
                end if
                rsObj.close
                set rsObj=nothing
            end if
            result=setxml(true)
		else
			result=setxml(false)
		end if
	else
		result=setxml(false)
	end if
	echo result
end sub

function setxml(byval t0)
	dim t1,t2
	if t0 then
		t1="SUCCESS"
		t2="OK"
	else
		t1="FAIL"
		t2="参数格式校验错误"
	end if
	dim str:str=""
	str=str&"<xml>"
	str=str&"<return_code>"&t1&"</return_code>"
	str=str&"<return_msg>"&t2&"</return_msg>"
	str=str&"</xml>"
	setxml=str
end function
deal_xml
%>

<script language="jscript" runat="server">
    Array.prototype.get = function(x) { return this[x]; };
    function parseJSON(strJSON) { return eval("(" + strJSON + ")"); }
</script>